﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.IO;
using System.Web.Security;

using System.Configuration;
using System.Text.RegularExpressions;
public partial class Admin_CandidateRegistration : System.Web.UI.Page
{
    #region events
    public string CVPath = ConfigurationSettings.AppSettings["TempCv"];
    public string TempDocumentPathExtention = ConfigurationSettings.AppSettings["ImageFileType"];
    public string TempDocumentPath = ConfigurationSettings.AppSettings["TempProfilePic"];
    public string CVPathRegistered = ConfigurationSettings.AppSettings["CvPath"];
    string profileresumefromdb = string.Empty;



    Int32 FileLimitSize = Convert.ToInt32(ConfigurationManager.AppSettings["FileLimitSize"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {


        if (!IsPostBack)
        {
            ViewState["dtWorkExp"] = null;
            ViewState["HdnResumeValue"] = "false";

            lblFormat.InnerText = "* Acceptable file formats: " + Convert.ToString(ConfigurationManager.AppSettings["ImageFileType"]).Replace("|", ", ") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblResume.InnerText = "* Acceptable file formats: " + Convert.ToString(ConfigurationManager.AppSettings["ResumeFileType"]).Replace("|", ",  ") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            LoadBindData();
            mvwCandidateReg.ActiveViewIndex = 0;
            btnPervious.Visible = false;
            btnFinish.Visible = false;
            rbtCandType.SelectedIndex = 0;
            rbtCandType_SelectedIndexChanged(sender, null);
            mnAccrd_MenuItemClick(sender, null);
            gvAddWorkExp.DataBind();


        }

    }

    private void LoadBindData()
    {
        //--------
        ActivityMasterBAL objActMstBAL = new ActivityMasterBAL();
        DataSet objjActMstDs = new DataSet();

        objjActMstDs = objActMstBAL.GetActivityByActivityType("ACCREDITATIONTYPE");
        CommonUtility.BindDropDown(ref ddlAccreType, objjActMstDs, "ActivityName", "ActivityCode");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlAccreType);
        //brijal added for previously applied and pass combos box
        CommonUtility.BindDropDown(ref ddlApplyAccrediationType, objjActMstDs, "ActivityName", "ActivityCode");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlApplyAccrediationType);
        CommonUtility.BindDropDown(ref ddlPassAccrediationType, objjActMstDs, "ActivityName", "ActivityCode");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlPassAccrediationType);

        objjActMstDs = objActMstBAL.GetActivityByActivityType("CANDIDATETYPE");
        CommonUtility.BindRadioButtonList(ref rbtCandType, objjActMstDs, "ActivityName", "ActivityCode");

        objjActMstDs = objActMstBAL.GetCountryMasterActive();
        CommonUtility.BindDropDown(ref ddlNationality, objjActMstDs, "CountryName", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNationality);

        //objjActMstDs = objActMstBAL.GetActivityByActivityType("NATIONALIT");
        //CommonUtility.BindDropDown(ref ddlNationality, objjActMstDs, "ActivityName", "ActivityID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNationality);

        objjActMstDs = objActMstBAL.GetActivityByActivityType("GRADUATION");
        CommonUtility.BindDropDown(ref ddlGraduation, objjActMstDs, "ActivityName", "ActivityID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlGraduation);

        //objjActMstDs = objActMstBAL.GetActivityByActivityType("SPECIALIZATION");
        //CommonUtility.BindDropDown(ref ddlSpecialization, objjActMstDs, "ActivityName", "ActivityID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlSpecialization);

        objjActMstDs = objActMstBAL.GetActivityByActivityType("QUALIFICATIONSTATUS");
        CommonUtility.BindDropDown(ref ddlQuliStatus, objjActMstDs, "ActivityName", "ActivityID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlQuliStatus);


        objjActMstDs = objActMstBAL.GetCountryMasterActive();

        CommonUtility.BindDropDown(ref ddlCountry, objjActMstDs, "CountryName", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlCountry);

        CommonUtility.BindDropDown(ref ddlhCountryCode, objjActMstDs, "CountryTelCode", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlhCountryCode);

        //CommonUtility.BindDropDown(ref ddlMCountryCode, objjActMstDs, "CountryTelCode", "CountryID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlMCountryCode);

        DataView objDv = new DataView();
        //DataTable uniqueCols = objjActMstDs.Tables[0].DefaultView.ToTable(true, "CountryTelCode");

        var lselColumns = new[] { "CountryTelCode" };
        DataTable uniqueCols = objjActMstDs.Tables[0].DefaultView.ToTable(true, lselColumns);
        objDv = uniqueCols.DefaultView;
        objDv.Sort = "CountryTelCode ASC";



        CommonUtility.BindDropDown(ref ddlWCountryCode, objDv, "CountryTelCode", "CountryTelCode");
        // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlWCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlWCountryCode);

        // AddSelectToDDLWithOnlySelect

        CommonUtility.BindDropDown(ref ddlOCountryCode, objDv, "CountryTelCode", "CountryTelCode");
        // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlOCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlOCountryCode);

        CommonUtility.BindDropDown(ref ddlMCountryCode, objDv, "CountryTelCode", "CountryTelCode");
        //  CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlMCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlMCountryCode);

        //brijal comment for load language after country selected by candidate 06112017
        //LanugageMasterBAL objLangMstBAL = new LanugageMasterBAL();
        //objjActMstDs = objLangMstBAL.GetLanguageMasterActive();
        //CommonUtility.BindCheckBoxList(ref chkLanguage, objjActMstDs, "LanguageName", "LanguageID");

        ddlNoYearCurrentRole.DataSource = Enumerable.Range(0, 50).ToList();
        ddlNoYearCurrentRole.DataBind();
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlNoYearCurrentRole);

        ddlNoModeratorYearExp.DataSource = Enumerable.Range(0, 50).ToList();
        ddlNoModeratorYearExp.DataBind();
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlNoModeratorYearExp);

        ddlRLExperience.DataSource = Enumerable.Range(0, 50).ToList();
        ddlRLExperience.DataBind();
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlRLExperience);

        //brijal add for hiding previous data
        trApplyAccrediationType.Visible = false;
        trFinalResult.Visible = false;
        trPassAccrediationType.Visible = false;
        trAssessorName.Visible = false;
        //

        DataSet objUMBDs = new DataSet();
        UserMasterBAL objUMB = new UserMasterBAL();
        Guid roleGuid = new Guid("12366510-AEF2-45FD-A59C-C69099B56545");
        objUMBDs = objUMB.GetUserNameByRole(roleGuid);
        //CommonUtility.BindRadioButtonList(ref ddlAssessorName, objUMBDs, "FirstName", "FirstName");
        CommonUtility.BindDropDown(ref ddlAssessorName, objUMBDs, "FirstName", "FirstName");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlAssessorName);
        CommonUtility.AddOtherToDropDown(ref ddlAssessorName);

    }

    protected void rbtCandType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtCandType.SelectedValue.ToUpper() == "INDEPENDENT")
        {
            txtMarketResearchCompany.Text = string.Empty;
            trCompanyName.Visible = false;
            trCompanySpace.Visible = false;


        }
        else if (rbtCandType.SelectedValue.ToUpper() == "CORPORATE")
        {
            trCompanyName.Visible = true;
            trCompanySpace.Visible = true;
        }

    }
    protected void mnAccrd_MenuItemClick(object sender, MenuEventArgs e)
    {
        int intActiveIndex;
        if (e != null)
        {
            mvwCandidateReg.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        intActiveIndex = mvwCandidateReg.ActiveViewIndex;

        switch (intActiveIndex)
        {
            case 0:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = false;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = false;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 1:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 2:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 3:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 4:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                mainMenu.Items[4].Enabled = true;
                btnPervious.Visible = true;
                btnNext.Visible = false;
                btnFinish.Visible = true;
                break;
        } 
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            switch (mvwCandidateReg.ActiveViewIndex)
            {
                case 0:
                    mvwCandidateReg.ActiveViewIndex = 1;
                    btnPervious.Visible = true;
                    btnNext.Visible = true;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = false;
                    mainMenu.Items[3].Enabled = false;
                    mainMenu.Items[4].Enabled = false;
                    break;
                case 1:
                    mvwCandidateReg.ActiveViewIndex = 2;
                    btnPervious.Visible = true;
                    btnNext.Visible = true;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    mainMenu.Items[3].Enabled = false;
                    mainMenu.Items[4].Enabled = false;
                    hdnPassword.Value = txtPassword.Text.Trim();

                    break;
                case 2:
                    mvwCandidateReg.ActiveViewIndex = 3;
                    btnPervious.Visible = true;
                    btnNext.Visible = true;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    mainMenu.Items[3].Enabled = true;
                    mainMenu.Items[4].Enabled = false;
                    if (fuUploadPic.PostedFile.FileName != "")
                    {
                        TempFileSave("PROFILE");
                    }

                    break;
                case 3:
                    Boolean expVld = ChkWorkExperience();
                    if (expVld)
                    {
                        mvwCandidateReg.ActiveViewIndex = 4;
                        btnPervious.Visible = true;
                        btnNext.Visible = false;
                        btnFinish.Visible = true;
                        mainMenu.Items[0].Enabled = true;
                        mainMenu.Items[1].Enabled = true;
                        mainMenu.Items[2].Enabled = true;
                        mainMenu.Items[3].Enabled = true;
                        mainMenu.Items[4].Enabled = true;
                        //if (hdnResume.Value == "")
                        //{
                        //    rdbResume2.Checked = true;
                        //    rdbResum1e.Checked = false;
                        //}
                        //if (rdbResume1.Checked)
                        //{

                        //    TempFileSave("CV");

                        //}
                        //else
                        //{ 
                        //    profileresumefromdb = Convert.ToString(ViewState["strTempResumeTitle"]);
                        //}

                        if (Convert.ToString(ViewState["HdnResumeValue"]) == "false")
                        {
                            if (fuResume.PostedFile.FileName != "")
                            { TempFileSave("CV"); }
                        }
                        else
                        {
                            if (rdbResume1.Checked == true)
                            {
                                if (fuResume.PostedFile.FileName != "")
                                { TempFileSave("CV"); }
                            }
                        }
                        if (rdbResume2.Checked)
                        { }

                        //if (fuResume.PostedFile.FileName != "")
                        //{
                        //    TempFileSave("CV");
                        //}
                        //if (txtCompanyName.Text != "" || TxtTypeOfCompany.Text != "")
                        //{
                        //    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('To add Work Experience please click on Add Work Experience Button ');", true);

                        //}
                        PreviewDetail();
                    }
                    else
                    {
                        Response.Write("<script>alert('Add Work Experience');</script>");
                    }
                    break;
                    
            }
        }
    }
    protected void btnPervious_Click(object sender, EventArgs e)
    {
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 1:
                mvwCandidateReg.ActiveViewIndex = 0;
                btnPervious.Visible = false;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = false;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                break;
            case 2:
                mvwCandidateReg.ActiveViewIndex = 1;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = false;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                break;
            case 3:
                mvwCandidateReg.ActiveViewIndex = 2;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
                mainMenu.Items[4].Enabled = false;
                break;
            case 4:
                mvwCandidateReg.ActiveViewIndex = 3;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
                mainMenu.Items[4].Enabled = false;
                checkUploadedResume();
                break;
        }
    }

    #endregion

    private void checkUploadedResume()
    {
        if (hdnResume.Value.Trim().Length > 0)
        {
            tdUploadedResume.Visible = true;
            tdPreviousResumeView.Visible = true;
            fuResume.Enabled = false;

            string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
            string strCVPath = CVPath.Remove(0, 1);
            string strPath = string.Empty;

            strPath = strAuthority + strCVPath + Path.GetFileName(hdnResume.Value);

            tdPreviousResumeView.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Check Previous Uploaded Resume</b>" + "</a>";

            // tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";

            rdbResume1.Checked = false;
            rdbResume2.Checked = true;


            //string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;

            //string strPathPreResume = string.Empty;
            //string strPreDownResume = CVPath.Remove(0, 1);
            //string strCvTitle = Convert.ToString(ViewState["strTempResumeTitle"]); // Convert.ToString(DtCandidateData.Rows[0]["CVPath"]);





            //strPathPreResume = strAuthority + strPreDownResume + strCvTitle;

            //tdPreviousResumeView.InnerHtml = "<a href=javascript:onClickLink('" + strPathPreResume + "')>" + "<b>Check Previous Uploaded Resume</b>" + "</a>";
        }
        else
        {
            tdUploadedResume.Visible = false;
            fuResume.Enabled = true;
            tdPreviousResumeView.Visible = false;

        }
    }

    protected void rdbUploadResume_CheckedChanged(object sender, EventArgs e)
    {
        if (rdbResume1.Checked)
        { fuResume.Enabled = true; }
        else
            fuResume.Enabled = false;
    }
    private void ClearDataWorkExperience()
    {
        txtCompanyName.Text = "";
        txtCurrentRole.Text = "";
        TxtTypeOfCompany.Text = "";
        ddlNoYearCurrentRole.SelectedIndex = 0;
        ddlNoModeratorYearExp.SelectedIndex = 0;
        ddlRLExperience.SelectedIndex = 0;
        lblTotExpRLMod.Text = "";
        txtRemark.Text = "";
    }
    protected void btnAddWorkExp_Click(object sender, EventArgs e)
    {
        int intTOtalExp = Convert.ToInt32(ddlNoYearCurrentRole.SelectedValue.Trim());
        int intModExp = Convert.ToInt32(ddlNoModeratorYearExp.SelectedValue.Trim());
        int intRLExp = Convert.ToInt32(ddlRLExperience.SelectedValue.Trim());
        //int intModRLExp=(intModExp+intRLExp);
        if (intTOtalExp >= intModExp && intTOtalExp >= intRLExp)
        {
            if (Page.IsValid == true)
            {

                //Add wrok experience
                AddWorkExperience(txtCompanyName.Text.Trim(), TxtTypeOfCompany.Text.Trim(), txtCurrentRole.Text.Trim(), ddlNoYearCurrentRole.SelectedValue.Trim(), ddlNoModeratorYearExp.SelectedValue.Trim(), ddlRLExperience.SelectedValue.Trim(), txtRemark.Text.Trim());
                BindWorkExperience();
                ClearDataWorkExperience();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Work Experience added Successfully.');", true);

            }

        }
        else
        {
            if (intTOtalExp <= intModExp && intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience & Moderator Experience Years.";

            }
            else if (intTOtalExp <= intModExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Moderator Experience Years.";
            }
            else if (intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience.";
            }

            //args.IsValid = false;
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('company experience less than Research Lead Experience & Moderator Experience.');", true);
        }


    }

    private void BindWorkExperience()
    {

        gvAddWorkExp.DataSource = (DataTable)ViewState["dtWorkExp"];
        gvAddWorkExp.DataBind();
    }

    private Boolean ChkWorkExperience()
    {
        DataTable dtWorkExp;

        if (ViewState["dtWorkExp"] == null)
        {
            return false;
        }
        else
        {
            dtWorkExp = (DataTable)ViewState["dtWorkExp"];

            var querySum = (from qs in dtWorkExp.AsEnumerable()
                            select qs).Count();

            if (querySum > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    private void AddWorkExperience(string strCompnayName, string strTypeOfCompany, string strCurrentRole, string strNoYearCurrentRole, string strNOModeratorYearExp, string strNoRLExperience, string strRemarks)
    {
        DataTable dtWorkExp;

        if (ViewState["dtWorkExp"] == null)
        {
            dtWorkExp = new DataTable();
            dtWorkExp.Columns.Add("CompanyExpID");
            dtWorkExp.Columns.Add("CompanyName");
            dtWorkExp.Columns.Add("TypeOfCompany");
            dtWorkExp.Columns.Add("CurrentRole");
            dtWorkExp.Columns.Add("NoYearCurrentRole");
            dtWorkExp.Columns.Add("NoModeratorYearRole");
            dtWorkExp.Columns.Add("NoResearchYearRole");
            dtWorkExp.Columns.Add("Remarks");
        }
        else
        {
            dtWorkExp = (DataTable)ViewState["dtWorkExp"];
        }



        DataRow drWorkExp = dtWorkExp.NewRow();

        drWorkExp["CompanyExpID"] = (dtWorkExp.Rows.Count + 1);
        drWorkExp["CompanyName"] = strCompnayName;
        drWorkExp["TypeOfCompany"] = strTypeOfCompany;
        drWorkExp["CurrentRole"] = strCurrentRole;
        drWorkExp["NoYearCurrentRole"] = strNoYearCurrentRole;
        drWorkExp["NoModeratorYearRole"] = strNOModeratorYearExp;
        drWorkExp["NoResearchYearRole"] = strNoRLExperience;
        drWorkExp["Remarks"] = strRemarks;

        var querySum = (from qs in dtWorkExp.AsEnumerable()
                        where qs.Field<string>("CompanyName") == strCompnayName
                        select qs).Count();

        if (querySum <= 0)
        {
            dtWorkExp.Rows.Add(drWorkExp);
            ViewState["dtWorkExp"] = dtWorkExp;
        }
        else
        {
            Response.Write("The Record already exists in the table");
        }
    }

    protected void gvAddWorkExp_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            int id = int.Parse(gvAddWorkExp.Rows[e.RowIndex].Cells[1].Text);
            TextBox txtCompanyName = gvAddWorkExp.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox;
            TextBox txtTypeOfCompany = gvAddWorkExp.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;
            TextBox txtCurrentRole = gvAddWorkExp.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;

            DropDownList ddlTotalWrkExp = gvAddWorkExp.Rows[e.RowIndex].Cells[5].Controls[0] as DropDownList;
            DropDownList ddlModExp = gvAddWorkExp.Rows[e.RowIndex].Cells[6].Controls[0] as DropDownList;
            DropDownList ddlRLExp = gvAddWorkExp.Rows[e.RowIndex].Cells[7].Controls[0] as DropDownList;
            TextBox txtRemark = gvAddWorkExp.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;


        }
        catch (Exception ee)
        {
            Response.Write(ee.Message);
        }

    }

    protected void gvAddWorkExp_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        //int intCompanyExpID = (int)gvAddWorkExp.DataKeys[e.RowIndex].Value;
        //string strStatus = Convert.ToString(gvAddWorkExp.Rows[e.RowIndex].Cells[2].Text) == "Active" ? "DELETE" : "ACTIVE";
        //DeleteLanguage(intLanguageID, strStatus);
        //GetData();
        ((DataTable)ViewState["dtWorkExp"]).Rows.RemoveAt(e.RowIndex);
        BindWorkExperience();

    }


    protected void gvAddWorkExp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnBtn = (LinkButton)e.Row.FindControl("lnkDelete");
            lnBtn.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete " + DataBinder.Eval(e.Row.DataItem, "CompanyName") + " Company Name?')");
        }
    }
    protected void gvAddWorkExp_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvAddWorkExp.EditIndex = e.NewEditIndex;
        this.BindWorkExperience();
    }
    protected Boolean Human_Validate()
    {
        string EncodedResponse = Request.Form["g-Recaptcha-Response"];
        bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse) == "true" ? true : false);

        if (IsCaptchaValid)
        {
            return true;
            //Valid Request
        }
        else
        {
            return false;
        }
    }
    protected void btnFinish_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            if (Human_Validate())
            {
                string strReturnValue;
                CandidateMasterBO objCandidateMasterBO = new CandidateMasterBO();
                UserMasterBAL objUserMasterBAL = new UserMasterBAL();

                UserMasterBO objUserMasterBO = new UserMasterBO();
                objUserMasterBO.ApplicationName = "/";

                objUserMasterBO.RoleName = ddlAccreType.SelectedValue;
                objUserMasterBO.SetMethod = "INSERT";
                objCandidateMasterBO.AccrediationTypeCode = ddlAccreType.SelectedValue;
                objCandidateMasterBO.CandidateTypeCode = rbtCandType.SelectedValue;
                if (rbtCandType.SelectedValue == "CORPORATE")
                {
                    objCandidateMasterBO.MarketResearchCompany = txtMarketResearchCompany.Text;
                }
                else
                {
                    objCandidateMasterBO.MarketResearchCompany = string.Empty;
                }

                //TAB 2
                objUserMasterBO.EmailID = txtEmail.Text.Trim();
                objUserMasterBO.Password = hdnPassword.Value;
                objUserMasterBO.SecretQuestion = txtQuestion.Text.Trim();
                objUserMasterBO.SecretAnswer = txtAnswer.Text.Trim();
                objUserMasterBO.CreatedDate = System.DateTime.Now;

                //TAB 3
                objUserMasterBO.FirstName = txtFirstName.Text.Trim();
                objUserMasterBO.LastName = txtLastName.Text.Trim();
                objUserMasterBO.MiddleName = txtMiddleName.Text.Trim();
                //TODO
                //string strDate=Convert.ToString(txtDOB.Text.Trim());
                //DateTime date = Convert.ToDateTime(txtDOB.Text.Trim());
                //objUserMasterBO.DOBirth = CommonUtility.ConvertDateToMMddyyyy(txtDOB.Text.Trim());
                objUserMasterBO.DOBirth = "01/01/2001";
                //TODO
                objUserMasterBO.ProfilePicturePath = Path.GetFileName(hdnUploadPic.Value);
                //objUserMasterBO.Gender = rdbtnGender.SelectedValue;
                objUserMasterBO.Gender = "Male";
                objUserMasterBO.NationalityID = Convert.ToInt16(ddlNationality.SelectedValue);
                objCandidateMasterBO.LanguageList = LanguageList();
                UsersContactBO objUsersContactBO = new UsersContactBO();
                objUsersContactBO.ContactAddress = txtContactAdd.Text.Trim();
                objUsersContactBO.CountryID = Convert.ToInt16(ddlCountry.SelectedItem.Value);
                if (txtState.Text == "")
                {
                    objUsersContactBO.StateName = "-";
                }
                else
                {
                    objUsersContactBO.StateName = txtState.Text.Trim();
                }

                objUsersContactBO.ZipCode = txtZip.Text.Trim();
                objUsersContactBO.PhoneNo = ddlWCountryCode.SelectedItem.Value + "-" + txtWStdCode.Text.Trim() + "-" + txtWPhone.Text.Trim();
                objUsersContactBO.OtherPhoneNo = ddlOCountryCode.SelectedItem.Value + "-" + txtOStdCode.Text.Trim() + "-" + txtOPhone.Text.Trim();
                objUsersContactBO.MobileNo = ddlMCountryCode.SelectedItem.Value + "-" + txtMPhone.Text.Trim();
                //TAB 4
                UsersQualificationBO objUsersQualificationBO = new UsersQualificationBO();
                objUsersQualificationBO.GraduationID = Convert.ToInt16(ddlGraduation.SelectedValue);
                objUsersQualificationBO.QualificationSpecialization = txtSpecialization.Text.Trim();
                objUsersQualificationBO.University = txtUniversity.Text.Trim();
                objUsersQualificationBO.QualificationStatusID = Convert.ToInt16(ddlQuliStatus.SelectedValue);
                objUsersQualificationBO.ProCurrentRole = txtProCurrentRole.Text.Trim();
                objUsersQualificationBO.ProExperience = txtProExperience.Text.Trim();
                objUsersQualificationBO.ProfQualitative1 = txtProfQualitative1.Text.Trim();
                objUsersQualificationBO.ProfQualitative2 = txtProfQualitative2.Text.Trim();
                objUsersQualificationBO.ProfQualitative3 = txtProfQualitative3.Text.Trim();
                objUsersQualificationBO.ProfQualitative4 = txtProfQualitative4.Text.Trim();
                //brijal added
                objUsersQualificationBO.UserApplyBefore = Convert.ToByte(rdUserApplyBefore.SelectedValue);
                objUsersQualificationBO.ApplyAccrediationType = ddlApplyAccrediationType.SelectedValue;
                objUsersQualificationBO.FinalResult = Convert.ToByte(rdFinalResult.SelectedValue);
                objUsersQualificationBO.PassAccrediationType = ddlPassAccrediationType.SelectedValue;
                objUsersQualificationBO.AssessorName = ddlAssessorName.Text;


                if (((DataTable)ViewState["dtWorkExp"]) == null)
                {
                    objUserMasterBO.UserCompanyDetail = "<DocumentElement><Table1><CompanyExpID>0</CompanyExpID><CompanyName></CompanyName><TypeOfCompany></TypeOfCompany><CurrentRole></CurrentRole><NoYearCurrentRole></NoYearCurrentRole><NoModeratorYearRole></NoModeratorYearRole><NoResearchYearRole></NoResearchYearRole><Remarks></Remarks></Table1></DocumentElement>";
                }
                else
                {
                    DataTable dtWorkExp = new DataTable();
                    dtWorkExp = (DataTable)ViewState["dtWorkExp"];
                    if (dtWorkExp.Rows.Count > 0)
                    {
                        objUserMasterBO.UserCompanyDetail = CommonUtility.ConvertDatatableToXML(((DataTable)ViewState["dtWorkExp"]));
                    }
                    else
                    {
                        objUserMasterBO.UserCompanyDetail = "<DocumentElement><Table1><CompanyExpID>0</CompanyExpID><CompanyName></CompanyName><TypeOfCompany></TypeOfCompany><CurrentRole></CurrentRole><NoYearCurrentRole></NoYearCurrentRole><NoModeratorYearRole></NoModeratorYearRole><NoResearchYearRole></NoResearchYearRole><Remarks></Remarks></Table1></DocumentElement>";
                    }
                }

                objCandidateMasterBO.CVPath = Path.GetFileName(hdnResume.Value);
                strReturnValue = (string)objUserMasterBAL.SetCandidateMaster(objUserMasterBO, objCandidateMasterBO, objUsersContactBO, objUsersQualificationBO);
                MembershipUser User;
                if (strReturnValue == "SUCCESS")
                {
                    User = Membership.GetUser(txtEmail.Text.Trim(), false);
                    User.ChangePasswordQuestionAndAnswer("test@12345", txtQuestion.Text, txtAnswer.Text);

                    User.ChangePassword("test@12345", hdnPassword.Value);
                    UploadedFileMove();
                    Session["EmailID"] = txtEmail.Text.Trim();
                    Response.Redirect("~/Common/CandidateRegistrationThanks.aspx", true);
                    ViewState["dtWorkExp"] = null;
                }
                else if (strReturnValue == "EXIST")
                {

                    //Membership.DeleteUser(txtEmail.Text.Trim(), true);
                    // lblMessage.Text = "Activity Type already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //     
                    ViewState["dtWorkExp"] = null;
                }
                else
                {

                    ViewState["dtWorkExp"] = null;
                    // lblMessage.Text = "Error while saving record."; //EnrollResources.GetMessage(Message.FailedMessage); // 
                }
            }
            else
            {
                Response.Write("<script>alert('Please verify that you are not a robot.');</script>");
            }

        }
    }

    private int UploadedFileMove()
    {
        int intStatus = 0;
        string strProfileFilePath, strResumeFilePath;

        if (hdnUploadPic.Value != "")
        {
            strProfileFilePath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProfilePic"]) + Path.GetFileName(hdnUploadPic.Value));

            File.Move(hdnUploadPic.Value, strProfileFilePath);
        }

        if (hdnResume.Value != "")
        {
            strResumeFilePath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["CvPath"]) + Path.GetFileName(hdnResume.Value));
            File.Move(hdnResume.Value, strResumeFilePath);
        }
        return intStatus;

    }

    private string LanguageList()
    {
        string strLanguageList = string.Empty;
        for (int i = 0; i < chkLanguage.Items.Count; i++)
        {
            if (chkLanguage.Items[i].Selected)
            {
                strLanguageList += chkLanguage.Items[i].Value + ",";
            }
        }
        return strLanguageList.Substring(0, (strLanguageList.Length - 1));
    }


    private int LanguageSelected()
    {
        int intCount = 0;
        for (int i = 0; i < chkLanguage.Items.Count; i++)
        {
            if (chkLanguage.Items[i].Selected)
            {
                intCount = 1;
                return intCount;
            }
        }
        return intCount;
    }

    protected void cstLanguage_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (LanguageSelected() <= 0)
        {
            args.IsValid = false;
            return;
        }
    }

    protected void cvMobileNoValidation_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (Convert.ToInt64(txtMPhone.Text.Trim()) == 0)
        {
            args.IsValid = false;
            return;
        }
    }

    protected void gvAddWorkExp_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvAddWorkExp.EditIndex = -1;
        BindWorkExperience();
    }

    private int CompanyValidate()
    {
        int intCount = 0;
        if (ViewState["dtWorkExp"] != null)
        {
            DataTable dtWorkExp;
            dtWorkExp = (DataTable)ViewState["dtWorkExp"];
            var querySum = (from qs in dtWorkExp.AsEnumerable()
                            where qs.Field<string>("CompanyName") == txtCompanyName.Text.Trim()
                            select qs).Count();

            if (querySum > 0)
            {
                //Response.Write("Company name already exists");
                intCount = 1;
                return intCount;
            }
        }
        return intCount;
    }
    protected void cvAddWorkExp_ServerValidate(object source, ServerValidateEventArgs args)
    {

        if (ViewState["vwResumeCmyID"] == null)
        {

            if (CompanyValidate() > 0)
            {
                args.IsValid = false;
                return;
            }
        }
        else
        {
            if (Convert.ToString(ViewState["CompanyNamevalidation"]) == txtCompanyName.Text.Trim())
            {
                args.IsValid = true;
                return;


            }
            else
            {
                if (CompanyValidate() > 0)
                {
                    args.IsValid = false;
                    return;
                }
            }

        }
    }
    protected void cstUploadPic_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (fuUploadPic.PostedFile == null)
        {

            return;
        }
        else
        {
            if (fuUploadPic.PostedFile.FileName == "")
            {
                //args.IsValid = false;
                //cstUploadPic.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fuUploadPic.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (fuUploadPic.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstUploadPic.ErrorMessage = "Select Valid file.";
                    return;
                }
                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(fuUploadPic.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstUploadPic.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }
                //int fileSize = fuUploadPic.PostedFile.ContentLength;
                //if (fileSize > (FileLimitSize))
                //{
                //    args.IsValid = false;
                //    cstUploadPic.ErrorMessage = "Image size should not be more than 5 MB.";
                //    return;
                //}
                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fuUploadPic.PostedFile.FileName) == true)
                {
                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(fuUploadPic.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ImageFileType"])) == false)
                    {
                        args.IsValid = false;
                        cstUploadPic.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                }
            }
        }

    }


    protected void cstResume_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (fuResume.PostedFile == null)
        {

            if (hdnResume.Value == "")
            {
                if (rdbResume1.Checked == true)
                {
                    args.IsValid = false;
                    cstResume.ErrorMessage = "Select File to Attach.";
                    return;
                }
            }
            else
            {
                if (rdbResume1.Checked == true)
                {
                    args.IsValid = false;
                    cstResume.ErrorMessage = "Select File to Attach.";
                    return;
                }

            }

            //args.IsValid = false;
            //cstResume.ErrorMessage = "Select File to Attach.";
            //return;
        }
        else
        {

            if (fuResume.PostedFile.FileName == "")
            {

                //if (hdnResume.Value == "")
                //{
                //    if (rdbResume2.Checked == false)
                //    {
                //        args.IsValid = false;
                //        cstResume.ErrorMessage = "Select File to Attach.";
                //        return;
                //    }
                //}
                //else
                //{
                //    if (rdbResume1.Checked == true)
                //    {
                //        args.IsValid = false;
                //        cstResume.ErrorMessage = "Select File to Attach.";
                //        return;
                //    }

                //}
                args.IsValid = false;
                cstResume.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fuResume.PostedFile.FileName != "")
            {


                if (fuResume.PostedFile.ContentLength == 0)
                {

                    //if (hdnResume.Value == "")
                    //{
                    //    if (rdbResume2.Checked == false)
                    //    {
                    //        args.IsValid = false;
                    //        cstResume.ErrorMessage = "Select File to Attach.";
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    if (rdbResume1.Checked == true)
                    //    {
                    //        args.IsValid = false;
                    //        cstResume.ErrorMessage = "Select File to Attach.";
                    //        return;
                    //    }

                    //}

                    args.IsValid = false;
                    cstResume.ErrorMessage = "Select Valid file.";
                    return;
                }

                //int fileSize = fuResume.PostedFile.ContentLength;

                //if (fileSize > (FileLimitSize))
                //{
                //    args.IsValid = false;
                //    cstResume.ErrorMessage = "Resume document size should not be more than 5 MB.";
                //    return;
                //}
                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fuResume.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(fuResume.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ResumeFileType"])) == false)
                    {

                        args.IsValid = false;
                        cstResume.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                }
            }
        }

    }

    private void TempFileSave(string strFileType)
    {
        string strPath = string.Empty;
        string strFileExt = string.Empty;
        string strFileName = string.Empty;

        if (strFileType == "PROFILE")
        {
            strFileExt = Path.GetExtension(fuUploadPic.PostedFile.FileName);

            strFileName = fuUploadPic.FileName.Replace(Convert.ToString(fuUploadPic.FileName), txtEmail.Text.Trim());
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["TempProfilePic"]));

            hdnUploadPic.Value = strPath + strFileName + "_ProfilePic" + strFileExt;
            //fuUploadPic.SaveAs(hdnUploadPic.Value);
            CommonUtility.SaveFile(fuUploadPic, strPath, strFileName + "_ProfilePic" + strFileExt);
        }
        else if (strFileType == "CV")
        {

            strFileExt = Path.GetExtension(fuResume.PostedFile.FileName);
            string emailnm = txtEmail.Text.Trim().Replace('.', '_');
            strFileName = fuResume.FileName.Replace(Convert.ToString(fuResume.FileName), emailnm);
            ViewState["strTempResumeTitle"] = strFileName + "_CV" + strFileExt;
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["TempCv"]));
            hdnResume.Value = strPath + strFileName + "_CV" + strFileExt;
            //fuResume.SaveAs(hdnResume.Value);
            CommonUtility.SaveFile(fuResume, strPath, strFileName + "_CV" + strFileExt);
            ViewState["HdnResumeValue"] = "true";
        }
    }


    protected void csvEmail_ServerValidate(object source, ServerValidateEventArgs args)
    {
        UserMasterBAL objUserMasterBAL = new UserMasterBAL();
        DataSet objDs = new DataSet();
        objDs = objUserMasterBAL.GetCandidateDetailsByEmailID(txtEmail.Text.Trim());
        if (objDs.Tables[0].Rows.Count > 0)
        {
            csvEmail.ErrorMessage = "Email id already exists.";
            args.IsValid = false;
        }
    }
    //protected void TotExpRLMod_ServerValidate(object source, ServerValidateEventArgs args)
    //{
    //      int intTOtalExp = Convert.ToInt32(ddlNoYearCurrentRole.SelectedValue.Trim());
    //    int intModExp= Convert.ToInt32(ddlNoModeratorYearExp.SelectedValue.Trim());
    //    int intRLExp= Convert.ToInt32(ddlRLExperience.SelectedValue.Trim());
    //    int intModRLExp=(intModExp+intRLExp);
    //    if (intTOtalExp >= intModRLExp)
    //    {
    //        TotExpRLMod.ErrorMessage = "company experience less than rl & mod exp.";
    //        args.IsValid = false;
    //    }

    //}

    private void PreviewDetail()
    {
        tdAccreditationType.InnerHtml = ddlAccreType.SelectedItem.Text;
        tdCandidateType.InnerHtml = rbtCandType.SelectedItem.Text;

        if (rbtCandType.SelectedValue.ToUpper() == "INDEPENDENT")
        {
            trMarketReserach.Visible = false;
            tdMarketResearch.InnerHtml = "";
        }
        else
        {
            trMarketReserach.Visible = true;
            tdMarketResearch.InnerHtml = txtMarketResearchCompany.Text;
        }
        string strPath = string.Empty;
        string strFileName = string.Empty;
        strFileName = Path.GetFileName(hdnUploadPic.Value);
        // strFileName = txtEmail.Text.Trim();
        if (strFileName == "")
        {
            Image1.ImageUrl = "~/Images/Unknown2.jpg";
        }
        else
        {
            Image1.ImageUrl = TempDocumentPath + strFileName;
        }



        tdEmail.InnerHtml = txtEmail.Text.Trim();
        tdSecretQuestion.InnerHtml = txtQuestion.Text.Trim();
        tdFirstName.InnerHtml = txtFirstName.Text.Trim();
        if (txtMiddleName.Text == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";

        }
        else
        {
            tdMiddleName.InnerHtml = txtMiddleName.Text.Trim();
        }
        tdLastName.InnerHtml = txtLastName.Text.Trim();



        //tdDOB.InnerHtml = txtDOB.Text.Trim();
        tdGender.InnerHtml = (rdbtnGender.SelectedValue == "M" ? "Male" : "Female");
        tdNationality.InnerHtml = ddlNationality.SelectedItem.Text;
        //tdLanguage.InnerHtml = LanguageList();
        tdContactAddress.InnerHtml = txtContactAdd.Text;
        tdCountry.InnerHtml = ddlCountry.SelectedItem.Text;
        //tdState.InnerHtml = txtState.Text;
        tdZip.InnerHtml = txtZip.Text;

        if (txtWStdCode.Text == "" || txtWPhone.Text == "")
        {
            tdWorkPhone.InnerHtml = "&nbsp;&nbsp;-";
        }
        else
        {
            tdWorkPhone.InnerHtml = (ddlWCountryCode.SelectedItem.Text == "--- Select ---" ? "" : ddlWCountryCode.SelectedItem.Text + "-") + "" + (txtWStdCode.Text == "--- Select ---" ? "" : txtWStdCode.Text + "-") + "" + (txtWPhone.Text == "--- Select ---" ? "" : txtWPhone.Text);
        }
        tdMobileNo.InnerHtml = ddlMCountryCode.SelectedItem.Text + "-" + txtMPhone.Text;

        if (txtOStdCode.Text == "" || txtOPhone.Text == "")
        { tdOtherPhone.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdOtherPhone.InnerHtml = (ddlOCountryCode.SelectedItem.Text == "--- Select ---" ? "" : ddlOCountryCode.SelectedItem.Text + "-") + "" + (txtOStdCode.Text == "--- Select ---" ? "" : txtOStdCode.Text + "-") + "" + (txtOPhone.Text == "--- Select ---" ? "" : txtOPhone.Text);
        }
        tdGraduation.InnerHtml = ddlGraduation.SelectedItem.Text;
        tdSpecialization.InnerHtml = txtSpecialization.Text;
        tdUniversity.InnerHtml = txtUniversity.Text;
        tdStatus.InnerHtml = ddlQuliStatus.SelectedItem.Text;

        tdProCurrentRole.InnerHtml = txtProCurrentRole.Text;
        tdProExperience.InnerHtml = txtProExperience.Text;
        tdProfQualitative1.InnerHtml = txtProfQualitative1.Text;
        tdProfQualitative2.InnerHtml = txtProfQualitative2.Text;
        tdProfQualitative3.InnerHtml = txtProfQualitative3.Text;
        tdProfQualitative4.InnerHtml = txtProfQualitative4.Text;


        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
        string strCVPath = CVPath.Remove(0, 1);

        strPath = strAuthority + strCVPath + Path.GetFileName(hdnResume.Value);

        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";


        if (ViewState["dtWorkExp"] != null)
        {
            DataTable dtWorkExp = new DataTable();
            dtWorkExp = (DataTable)ViewState["dtWorkExp"];
            if (dtWorkExp.Rows.Count > 0)
            {
                trCompanyDetail.Visible = true;
                trCompanyDetailSpace.Visible = true;
                gvCompanyDetails.DataSource = (DataTable)ViewState["dtWorkExp"];
                gvCompanyDetails.DataBind();
                trCompanyDetailHead.Visible = true;
                trCompanyDetailSpace.Visible = true;
            }
            else
            {

                trCompanyDetailHead.Visible = false;
                trCompanyDetailSpace.Visible = false;
                trCompanyDetail.Visible = false;
                trCompanyDetailSpace.Visible = false;
            }

        }
        else
        {
            trCompanyDetailHead.Visible = false;
            trCompanyDetailSpace.Visible = false;
            trCompanyDetail.Visible = false;
            trCompanyDetailSpace.Visible = false;
        }
    }

    protected void hdnUploadPic_ValueChanged(object sender, EventArgs e)
    {

    }

    protected void OnLnkDownload_Click(object sender, EventArgs e)
    {
        //LinkButton lnkbtn = sender as LinkButton;
        ////GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        ////string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        //Response.ContentType = "image/jpg";
        //Response.AddHeader("Content-Disposition", "attachment;filename=\"" + CVPath + "\"");
        //Response.TransmitFile(Server.MapPath(filePath));
        //Response.End();
        string pathfilename = Path.GetFileName(hdnResume.Value);

        string strPath = CVPath + pathfilename;
        //string path = Server.MapPath();
        System.IO.FileInfo file = new System.IO.FileInfo(strPath);
        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
        else
        {
            Response.Write("This file does not exist.");
        }



    }
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {

        ddlhCountryCode.SelectedIndex = ddlhCountryCode.Items.IndexOf(ddlhCountryCode.Items.FindByValue(Convert.ToString(ddlCountry.SelectedValue)));
        string temp = (string)ddlhCountryCode.Items[ddlhCountryCode.SelectedIndex].Text;
        ddlMCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));
        ddlWCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));
        ddlOCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));

        CountryMasterBAL objCntryMstBAL = new CountryMasterBAL();
        DataSet ds = objCntryMstBAL.GetCountryLanguageByCountryID(ddlCountry.SelectedValue);
        CommonUtility.BindCheckBoxList(ref chkLanguage, ds, "LanguageName", "LanguageID");


    }
    protected void ddlAccreType_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void mvwCandidateReg_ActiveViewChanged(object sender, EventArgs e)
    {
        mainMenu.Items[0].Text = mainMenu.Items[0].Text.RemoveHTMLTags();
        mainMenu.Items[1].Text = mainMenu.Items[1].Text.RemoveHTMLTags();
        mainMenu.Items[2].Text = mainMenu.Items[2].Text.RemoveHTMLTags();
        mainMenu.Items[3].Text = mainMenu.Items[3].Text.RemoveHTMLTags();
        mainMenu.Items[4].Text = mainMenu.Items[4].Text.RemoveHTMLTags();
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 0:
                mainMenu.Items[0].Text = "<b><font color='blue'>" + mainMenu.Items[0].Text + "</font></b>";
                break;
            case 1:
                mainMenu.Items[1].Text = "<b><font color='blue'>" + mainMenu.Items[1].Text + "</font></b>";
                break;
            case 2:
                mainMenu.Items[2].Text = "<b><font color='blue'>" + mainMenu.Items[2].Text + "</font></b>";
                break;
            case 3:
                mainMenu.Items[3].Text = "<b><font color='blue'>" + mainMenu.Items[3].Text + "</font></b>";
                break;
            case 4:
                mainMenu.Items[4].Text = "<b><font color='blue'>" + mainMenu.Items[4].Text + "</font></b>";
                break;

        }
    }
    protected void gvAddWorkExp_SelectedIndexChanged(object sender, EventArgs e)
    {
        //gvAddWorkExp.DataKeys[gvAddWorkExp.].
        //string CompanyId = gvAddWorkExp.SelectedRow.Cells[0].Text;
        //txtCompanyName.Text = gvAddWorkExp.SelectedRow.Cells[1].Text;
        //TxtTypeOfCompany.Text = gvAddWorkExp.SelectedRow.Cells[2].Text;
        //txtCurrentRole.Text = gvAddWorkExp.SelectedRow.Cells[3].Text;


        string txtCompName = gvAddWorkExp.SelectedRow.Cells[1].Text;
        txtCompanyName.Text = txtCompName.Replace("amp;", "");
        ViewState["CompanyNamevalidation"] = txtCompName;
        string txtTypeOfComp = gvAddWorkExp.SelectedRow.Cells[2].Text;
        TxtTypeOfCompany.Text = txtTypeOfComp.Replace("amp;", "");
        string txtCurrentRo = gvAddWorkExp.SelectedRow.Cells[3].Text;
        txtCurrentRole.Text = txtCurrentRo.Replace("amp;", "");

        //  string  totalexpYear = (gvAddWorkExp.SelectedRow.Cells[4].Text);
        ddlNoYearCurrentRole.SelectedValue = ddlNoYearCurrentRole.Items.FindByText(gvAddWorkExp.SelectedRow.Cells[4].Text).Value;
        ddlNoModeratorYearExp.SelectedValue = ddlNoModeratorYearExp.Items.FindByText(gvAddWorkExp.SelectedRow.Cells[5].Text).Value;
        ddlRLExperience.SelectedValue = ddlRLExperience.Items.FindByText(gvAddWorkExp.SelectedRow.Cells[6].Text).Value;

        string strtxtRemark = gvAddWorkExp.SelectedRow.Cells[7].Text;
        txtRemark.Text = strtxtRemark.Replace("&nbsp;", "");

        divUpdateButtons.Visible = true;
        btnAddWorkExp.Visible = false;

        //string data = Convert.ToString(gvAddWorkExp.SelectedRow.Cells[0].Text);
        //ViewState["vwResumeCmyID"] = data;
        int rowIndex = gvAddWorkExp.SelectedIndex;

        string strValue = gvAddWorkExp.DataKeys[rowIndex].Value.ToString();

        ViewState["vwResumeCmyID"] = strValue;
        // txtCompanyName.Focus();
        txtRemark.Focus();
        btnNext.Enabled = false;
        btnPervious.Enabled = false;
        gvAddWorkExp.Enabled = false;

    }
    protected void BtnUpdateWorkExp_Click(object sender, EventArgs e)
    {

        int intTOtalExp = Convert.ToInt32(ddlNoYearCurrentRole.SelectedValue.Trim());
        int intModExp = Convert.ToInt32(ddlNoModeratorYearExp.SelectedValue.Trim());
        int intRLExp = Convert.ToInt32(ddlRLExperience.SelectedValue.Trim());
        //int intModRLExp=(intModExp+intRLExp);

        if (intTOtalExp >= intModExp && intTOtalExp >= intRLExp)
        {
            if (Page.IsValid == true)
            {

                //Add wrok experience
                AddEditedWorkExperience(txtCompanyName.Text.Trim(), TxtTypeOfCompany.Text.Trim(), txtCurrentRole.Text.Trim(), ddlNoYearCurrentRole.SelectedValue.Trim(), ddlNoModeratorYearExp.SelectedValue.Trim(), ddlRLExperience.SelectedValue.Trim(), txtRemark.Text.Trim());
                BindWorkExperience();
                ClearDataWorkExperience();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Work Experience Edited Successfully.');", true);
                divUpdateButtons.Visible = false;
                btnAddWorkExp.Visible = true;
                ViewState["vwResumeCmyID"] = null;
                ViewState["CompanyNamevalidation"] = null;
                btnNext.Enabled = true;
                btnPervious.Enabled = true;
                gvAddWorkExp.Enabled = true;
            }

        }
        else
        {
            if (intTOtalExp <= intModExp && intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience & Moderator Experience Years.";

            }
            else if (intTOtalExp <= intModExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Moderator Experience Years.";
            }
            else if (intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience.";
            }

            //args.IsValid = false;
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('company experience less than Research Lead Experience & Moderator Experience.');", true);
        }
    }
    protected void BtnCancelRecord_Click(object sender, EventArgs e)
    {
        divUpdateButtons.Visible = false;
        btnAddWorkExp.Visible = true;
        ClearDataWorkExperience();
        btnNext.Enabled = true;
        btnPervious.Enabled = true;
        gvAddWorkExp.Enabled = true;
    }

    private void AddEditedWorkExperience(string strCompnayName, string strTypeOfCompany, string strCurrentRole, string strNoYearCurrentRole, string strNOModeratorYearExp, string strNoRLExperience, string strRemarks)
    {
        DataTable dtWorkExp;



        dtWorkExp = (DataTable)ViewState["dtWorkExp"];


        string resumecompanyId = Convert.ToString(ViewState["vwResumeCmyID"]);

        foreach (DataRow dr in dtWorkExp.Rows)
        {
            if (Convert.ToString(dr["CompanyExpID"]) == resumecompanyId)
            {
                dr["CompanyName"] = strCompnayName;
                dr["TypeOfCompany"] = strTypeOfCompany;
                dr["CurrentRole"] = strCurrentRole;
                dr["NoYearCurrentRole"] = strNoYearCurrentRole;
                dr["NoModeratorYearRole"] = strNOModeratorYearExp;
                dr["NoResearchYearRole"] = strNoRLExperience;
                dr["Remarks"] = strRemarks;
            }
        }
        dtWorkExp.AcceptChanges();
        gvAddWorkExp.DataSource = dtWorkExp;
        gvAddWorkExp.DataBind();
        ViewState["dtWorkExp"] = dtWorkExp;





        //var querySum = (from qs in dtWorkExp.AsEnumerable()
        //                where qs.Field<string>("CompanyName") == strCompnayName
        //                select qs).Count();

        //if (querySum <= 0)
        //{
        //   // dtWorkExp.Rows.Add(drWorkExp);
        //    ViewState["dtWorkExp"] = dtWorkExp;
        //}
        //else
        //{
        //    Response.Write("The Record already exists in the table");
        //}
    }
    protected void rdUserApplyBefore_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rdUserApplyBefore.SelectedValue == "0")
        {
            ddlApplyAccrediationType.SelectedValue = "0";
            rdFinalResult.SelectedValue = "0";
            ddlPassAccrediationType.SelectedValue = "0";
            ddlAssessorName.SelectedValue = "0";

            trApplyAccrediationType.Visible = false;
            trFinalResult.Visible = false;
            trPassAccrediationType.Visible = false;
            trAssessorName.Visible = false;


        }
        else 
        {
            trApplyAccrediationType.Visible = true;
            trFinalResult.Visible = true;
            trPassAccrediationType.Visible = false;
            trAssessorName.Visible = true;
        }

    }

    protected void rdFinalResult_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rdFinalResult.SelectedValue == "0")
        {
            ddlPassAccrediationType.SelectedValue = "0";
            trPassAccrediationType.Visible = false;
        }
        else
        {
            trPassAccrediationType.Visible = true;
        }
    }
}